﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using YiSha.Util;
using YiSha.Util.Extension;
using YiSha.Util.Model;
using YiSha.Entity.QixingManage;
using YiSha.Model.Param.QixingManage;
using YiSha.Service.QixingManage;
using YiSha.Model.Result.QixingManage;

namespace YiSha.Business.QixingManage
{
    /// <summary>
    /// 创 建：admin
    /// 日 期：2023-03-19 19:46
    /// 描 述：订单详情业务类
    /// </summary>
    public class OrderDetailBLL
    {
        private OrderDetailService orderDetailService = new OrderDetailService();

        #region 获取数据
        public async Task<TData<List<OrderDetailEntity>>> GetList(OrderDetailListParam param)
        {
            TData<List<OrderDetailEntity>> obj = new TData<List<OrderDetailEntity>>();
            obj.Data = await orderDetailService.GetList(param);
            obj.Total = obj.Data.Count;
            obj.Tag = 1;
            return obj;
        }

        public async Task<TData<List<OrderDetailEntity>>> GetPageList(OrderDetailListParam param, Pagination pagination)
        {
            TData<List<OrderDetailEntity>> obj = new TData<List<OrderDetailEntity>>();
            obj.Data = await orderDetailService.GetPageList(param, pagination);
            obj.Total = pagination.TotalCount;
            obj.Tag = 1;
            return obj;
        }

        public async Task<TData<List<OrderDetailDto>>> GetPageDetailList(OrderDetailListParam param, Pagination pagination)
        {
            TData<List<OrderDetailDto>> obj = new TData<List<OrderDetailDto>>();
            obj.Data = await orderDetailService.GetPageDetailList(param, pagination);
            obj.Total = pagination.TotalCount;
            obj.Tag = 1;
            return obj;
        }
        public async Task<TData<List<OrderDetailDto>>> GetPageColourDetailList(OrderDetailListParam param, Pagination pagination)
        {
            TData<List<OrderDetailDto>> obj = new TData<List<OrderDetailDto>>();
            obj.Data = await orderDetailService.GetNewPageColourDetailList(param, pagination);
            obj.Total = pagination.TotalCount;
            obj.Tag = 1;
            return obj;
        }
        


        public async Task<TData<OrderDetailEntity>> GetEntity(long id)
        {
            TData<OrderDetailEntity> obj = new TData<OrderDetailEntity>();
            obj.Data = await orderDetailService.GetEntity(id);
            if (obj.Data != null)
            {
                obj.Tag = 1;
            }
            return obj;
        }

        public Task<List<OrderDetailEntity>> GetList(long oid)
        {
            var list=orderDetailService.GetList(oid);
            return list;
        }
        #endregion

        #region 提交数据
        public async Task<TData<string>> SaveForm(OrderDetailEntity entity)
        {
            TData<string> obj = new TData<string>();
            await orderDetailService.SaveForm(entity);
            obj.Data = entity.Id.ParseToString();
            obj.Tag = 1;
            return obj;
        }

        public async Task<TData<string>> OrderDetailSaveFormJson(OrderDetailEntity entity)
        {
            TData<string> obj = new TData<string>();
            var data=await orderDetailService.GetEntity(entity.Id.Value);
            if (data!=null)
            {
                data.productids = entity.productids;
                long[] idArr = TextHelper.SplitToArray<long>(entity.productids, ',');
                if (idArr.Length>0) {
                    data.pw_id = idArr[0];
                }
                await orderDetailService.OrderDetailSaveFormJson(data);
            }
            obj.Data = entity.Id.ParseToString();
            obj.Tag = 1;
            return obj;
        }
        

        public async Task<TData> DeleteForm(string ids)
        {
            TData obj = new TData();
            await orderDetailService.DeleteForm(ids);
            obj.Tag = 1;
            return obj;
        }
        #endregion

        #region 私有方法
        #endregion
    }
}
